package health.lm.com.mine.activity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.lm.sjy.titlebar.widget.CommonTitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import health.lm.com.component_base.base.mvp.activity.XActivity;
import health.lm.com.mine.R;
import health.lm.com.mine.R2;
import health.lm.com.mine.entity.AboutUsEntity;
import health.lm.com.mine.entity.CardInfoEntity;
import health.lm.com.mine.entity.InstructionEntity;
import health.lm.com.mine.entity.JiFenEntity;
import health.lm.com.mine.present.InfoWebviewPresenter;
import health.lm.com.router.ARouterConstant;

/**
 * 介绍说明webview
 * 卡券使用说明，关于我们，服务协议
 *
 * @author Administrator
 */
@Route(path = ARouterConstant.InfoWebviewActivity)
public class InfoWebviewActivity extends XActivity<InfoWebviewPresenter> {

    @BindView(R2.id.title_bar)
    CommonTitleBar titlebar;
    @BindView(R2.id.wv_info)
    WebView wvInfo;
    @Autowired
    int type = 0;
    @Autowired
    String topbar_title = "";

    @Override
    public int getLayoutId() {
        return R.layout.activity_info_webview;
    }

    @Override
    public InfoWebviewPresenter newP() {
        return new InfoWebviewPresenter();
    }

    @SuppressLint("CheckResult")
    @Override
    public void initData(Bundle savedInstanceState) {
        //返回按钮
        titlebar.setListener((v, action, extra) -> finish());
        titlebar.getCenterTextView().setText(topbar_title);
        if(type == ARouterConstant.CARD_INFO){
            getP().getCardInfo();
        }else if (type == ARouterConstant.ABOUT_US){
            getP().getAboutUs();
        }else if (type == ARouterConstant.INSTRUCTIONS){
            getP().getInstrution();
        }else if (type == ARouterConstant.JIFEN){
            getP().getJiFen();
        }else if (type == ARouterConstant.REGISTER){
            getP().getRegisterAgreement();
        }
    }
    /* 卡券使用说明*/
    public void getCardInfoSuccess(CardInfoEntity entity){
        setWebView(entity.getCard_explain());
    }
    /* 关于我们*/
    public void getAboutUsSuccess(AboutUsEntity entity){
        setWebView(entity.getAbout_us());
    }
    /* 使用说明*/
    public void getInstructionSuccess(InstructionEntity entity){
        setWebView(entity.getExplain());
    }
    /* 积分说明*/
    public void getJifensm(JiFenEntity entity){
        setWebView(entity.getCredit_explain());
    }
    /* 注册协议*/
    public void getRegisterAgreement(JiFenEntity entity){
        setWebView(entity.getTreaty());
    }

    private void setWebView(String url){
        wvInfo.loadDataWithBaseURL(null, url, "text/html", "UTF-8", null);
    }

}
